package com.estar.assistsurvy.adapter;

import java.util.List;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.grabList;
import com.estar.assistsurvy.utils.TimeUtils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TaskSuperviseAdapter extends BaseAdapter {

	private List<grabList> grbaList;
	private LayoutInflater inflater;

	public TaskSuperviseAdapter(List<grabList> grbaList, Context context) {
		super();
		this.grbaList = grbaList;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return grbaList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return grbaList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.listview_task, null);
			holder=new ViewHolder();
			holder.taskInfo=(TextView) convertView.findViewById(R.id.taskInfo);
			holder.addInfo=(TextView) convertView.findViewById(R.id.addInfo);
			holder.timeInfo=(TextView) convertView.findViewById(R.id.timeInfo);
			holder.taskState=(TextView) convertView.findViewById(R.id.taskState);
			holder.btn_more=(ImageView) convertView.findViewById(R.id.btn_more);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}

		grabList grba=grbaList.get(position);
		holder.taskInfo.setText(grba.getTargetCar()+"\t\t"+grba.getCaseNumber());
		holder.addInfo.setText(grba.getOccurPlace());
		holder.timeInfo.setText(TimeUtils.getHours(grba.getCreateTime()));
		holder.btn_more.setImageResource(R.drawable.btn_more);
		int caseState=Integer.parseInt(grba.getCaseState());
		switch (caseState) {
		case 1:
			holder.taskState.setText("未抢单");
			break;

		case 2:
			holder.taskState.setText("抢单终止");
			break;

		case 3:
			holder.taskState.setText("已抢单");
			break;

		case 4:
			holder.taskState.setText("放弃抢单");
			break;

		case 5:
			holder.taskState.setText("注销");
			break;

		case 6:
			holder.taskState.setText("已完成");
			break;
			
		default:
			break;
		}

		return convertView;
	}

	private class ViewHolder{
		private TextView taskInfo,addInfo,timeInfo,taskState;
		private ImageView btn_more;
	}

}
